package main

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"log"
)


func main(){
	// 1.创建一个学生的结构体
	type Register struct {
		UserName string `form:"name"`
		Phone string `form:"phone"`
		Password string `form:"password"`

	}

	r := gin.Default()
	//http://127.0.0.1:8000/hello
	r.POST("/hello", func(context *gin.Context) {
		fmt.Println(context.FullPath())

		// 2.创建一个结构体的实例 通过 context.ShouldBind(&stu) 的方式去绑定
		var register Register
		err := context.ShouldBind(&register)
		if err!=nil{
			log.Fatal(err.Error())
			return
		}
		fmt.Println(register.UserName)
		fmt.Println(register.Phone)
		fmt.Println(register.Password)
		context.Writer.Write([]byte("Register,"+register.UserName))
	})
	r.Run("127.0.0.1:8002")
}

